package com.breaktian.assemble.customviews.viewpager.cursorviewpager;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by tiankeke on 2017/6/21.
 * FragmentStatePagerAdapter 只保留当前页 划出视线就销毁
 * FragmentPagerAdapter 保留所有的pager 适合数据量不大的情况
 */

public class CursorPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragments;

    public CursorPagerAdapter(FragmentManager fm) {
        super(fm);
    }
    public CursorPagerAdapter(FragmentManager fm,List<Fragment> fragments) {
        super(fm);
        setData(fragments);
    }


    public void setData(List<Fragment> fragmenets){
        this.mFragments = fragmenets;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        if(mFragments!=null&&mFragments.size()>0){
            return mFragments.get(position);
        }
        return null;
    }

    @Override
    public int getCount() {
        if(mFragments!=null){
            return mFragments.size();
        }
        return 0;
    }
}
